﻿
function getVcode() {
    $.ajax({
        url: '/demo1_war_exploded/API/Code',
        type: 'GET',
        dataType: 'json',
        success: function (response) {
            console.log('收到数据:', response);
            Vcode = response.timestamp
            alert('验证码为:' + Vcode);
            // 在这里更新页面内容而不刷新
            $('#result').text(response.message);
        },
        error: function (xhr) {
            console.error('请求失败:', xhr.statusText);
        }
    });
}


 function getUserInfo(username, password) {
    return new Promise((resolve, reject) => {
        $.ajax({
            url: '/demo1_war_exploded/API/login',
            type: 'POST',
            dataType: 'json',
            data: {
                username: username,
                password: password
            },
            success: function (response) {
                resolve(response.code); // 返回整个timestamp对象
            },
            error: function (xhr) {
                reject(new Error('请求失败: ' + xhr.statusText));
            }
        });
    });
}


function DoReg(username,password,contactInfo){
    return new Promise((resolve, reject) => {
        $.ajax({
            url: '/demo1_war_exploded/API/register',
            type: 'POST',
            dataType: 'json',
            data: {
                username: username,
                password: password,
                EmailOrPhone:contactInfo
            },
            success: function (response) {
                resolve(response.code); // 返回整个timestamp对象
            },
            error: function (xhr) {
                reject(new Error('请求失败: ' + xhr.statusText));
            }
        });
    });
}

function VerifyExistence(EmailorPhone){
    return new Promise((resolve, reject) => {
        $.ajax({
            url: '/demo1_war_exploded/API/verify',
            type: 'POST',
            dataType: 'json',
            data: {
                EmailOrPhone:EmailorPhone
            },
            success: function (response) {
                resolve(response.code); // 返回整个timestamp对象
            },
            error: function (xhr) {
                reject(new Error('请求失败: ' + xhr.statusText));
            }
        });
    });
}

// 定义一个重置密码的函数，参数为用户名、密码和联系方式
